
import { createStoreBindings } from "mobx-miniprogram-bindings"
import store from "../../store/piece"
import prodInfoApi from '../../api/prodInfo'
import enumApi from '../../api/enum'
Page({
  data: {
    logs: [],
    sphIndex:null,
    sphArray:['-10.0','-9.75','-9.5','-9.25','-9.0','-8.75','-8.5','-8.25','-8.0','-7.75','-7.5','-7.25','-7.0','-6.75','-6.5','-6.25','-6.0','-5.75','-5.5','-5.25','-5.0','-4.75','-4.5','-4.25','-4.0','-3.75','-3.5','-3.25','-3.0','-2.75','-2.5','-2.25','-2.0','-1.75','-1.5','-1.25','-1.0','-0.75','-0.5','-0.25','0','0.25','0.5','0.75','1.0','1.25','1.5','1.75','2.0','2.25','2.5','2.75','3.0','3.25','3.5','3.75','4.0','4.25','4.5','4.75','5.0','5.25','5.5','5.75','6.0','6.25','6.5','6.75','7.0','7.25','7.5','7.75','8.0','8.25','8.5','8.75','9.0','9.25','9.5','9.75','10.0'],
    cylArray:['-2.5','-2.25','-2.00','-1.75','-1.50','-1.25','-1.00','-0.75','-0.50','-0.25','0.25','0.50','0.75','1.00','1.25','1.50','1.75','2.00','2.25','2.50'],
    cylIndex:null,
    axisIndex:null,
    axisIndexArray:[],

    sphLeftIndex:null,
    cylLeftIndex:null,
    axisLeftIndex:null,
    axisLeftArray:[],
    cylLeftArray:['-2.5','-2.25','-2.00','-1.75','-1.50','-1.25','-1.00','-0.75','-0.50','-0.25','0.25','0.50','0.75','1.00','1.25','1.50','1.75','2.00','2.25','2.50'],
    sphLeftArray:['-10.0','-9.75','-9.5','-9.25','-9.0','-8.75','-8.5','-8.25','-8.0','-7.75','-7.5','-7.25','-7.0','-6.75','-6.5','-6.25','-6.0','-5.75','-5.5','-5.25','-5.0','-4.75','-4.5','-4.25','-4.0','-3.75','-3.5','-3.25','-3.0','-2.75','-2.5','-2.25','-2.0','-1.75','-1.5','-1.25','-1.0','-0.75','-0.5','-0.25','0','0.25','0.5','0.75','1.0','1.25','1.5','1.75','2.0','2.25','2.5','2.75','3.0','3.25','3.5','3.75','4.0','4.25','4.5','4.75','5.0','5.25','5.5','5.75','6.0','6.25','6.5','6.75','7.0','7.25','7.5','7.75','8.0','8.25','8.5','8.75','9.0','9.25','9.5','9.75','10.0'],

    //瞳距
    pdType:"1",
    frameType:"0",

    remark:"",
    pd:"",
    skuTags:[],
    properties:[],
    pic:"",
    leftOrRightTitle:"",
    tsjg:[],
    specialList:{},
    conditionList:{},
    prodNum:1,
    prodInFoId:null


  },
  onLoad(data) {
    this.storeBindings =  createStoreBindings(this, {
        store,
        fields:['prodInFo','formData','parameter'],
      })
      this.storeBindings.updateStoreBindings()
      console.log("this----->",this.data)

      let properties = this.data.prodInFo.properties
      this.setSkuList(properties)

      this.getProdInfo(data.id)
      this.setData({
        prodInFoId:data.id
      })
      this.enumSpecialProcess()
      this.enumSpecialCondition()
   
     
  },
  onUnload() {
    // 解绑
    this.storeBindings.destroyStoreBindings()
  },
  setSkuList(list) {
    const skuTags = []
    for (let i = 0; i < list.length; i++) {
      const sku = list[i]
      
   
    }
    // this.setData({
    //   skuTags
    // })
  },
  nextBtn() {
    let data = {
      right:{
        sph:this.data.sphArray[this.data.sphIndex],
        cyl:this.data.cylArray[this.data.cylIndex]
      },
      left:{
        sph:this.data.sphLeftArray[this.data.sphLeftIndex],
        cyl:this.data.cylLeftArray[this.data.cylLeftIndex]
      }
    }
    console.log("this.data------->",this.data)
    // pieceApi.prodSearch(JSON.stringify(data)).then(()=>{

    // })

    let toData = {
      formData:data,
      pdType:this.data.pdType,
      frameType:this.data.frameType,
      remark:this.data.remark,
      axisRight:this.data.axisIndexArray[this.data.axisIndex],
      axisLeft:this.data.axisLeftArray[this.data.axisLeftIndex],
      pd:this.data.pd

    }
    this.updateFormDataAction(toData)
    wx.navigateTo({
      url: '../brand/brand?formData='+toData
    })
  },
  getProdInfo(id) {
    prodInfoApi.getProdInfo(id).then((res)=>{
        let properties = res.properties
        let leftOrRight = res.leftOrRight
         let leftOrRightType = {
          1:'左眼',
          2:'右眼',
          3:'全部'
         }
        this.setData({
          properties,
          tsjg:res.tsjg,
          pic:'http://glasses.sflyers.com' + res.pic,
          leftOrRightTitle:leftOrRightType[leftOrRight]
        })
    })
  },
  enumSpecialProcess() {
    enumApi.enumSpecialProcess().then((res) => {
      let specialList = {}
      res.forEach(element => {
        specialList[element.id] = element.label
      });

      this.setData({
        specialList:specialList
      })
    })
  },
  enumSpecialCondition() {
    enumApi.enumSpecialCondition().then((res) => {
      let conditionList = {}
      res.forEach(element => {
        conditionList[element.id] = element.label
      });
      this.setData({
        conditionList:conditionList
      })
    })
  },
  orderBtn() {
    //下单
    wx.navigateTo({
      url: '../orderConfirm/orderConfirm?id='+ this.data.prodInFoId + '&prodNum='+this.data.prodNum
    })
  },
  onStepperChange(event) {
    this.setData({
      prodNum:event.detail
    })
  }
})